﻿/*************************************************************************
 * 
 * Filename :messagelist
 * 
 * steven hu   2010/3/11 10:34:24
 *  
 * http://www.cnblogs.com/huxj
 *   
 * 
 * Change History:
 * 
 * 
**************************************************************************/



using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hxj.Data;
using RicciWebsite.Model;
using System.Data;
using Hxj.Web;

namespace RicciWebsite.admin
{
    public partial class messagelist : RicciWebsite.Pages.AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData();
            }
        }



        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pager_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }


        /// <summary>
        /// 数据
        /// </summary>
        private void bindData()
        {
            WhereClip where = new WhereClip();
            if (!string.IsNullOrEmpty(txtTitle.Value.Trim()))
            {
                where = where.And(base_message._.mtitle.Contain(txtTitle.Value.Trim()));
            }

            if (!string.IsNullOrEmpty(txtStart.Value.Trim()))
            {
                where = where.And(base_message._.subtime >= txtStart.Value);
            }

            if (!string.IsNullOrEmpty(txtEnd.Value.Trim()))
            {
                where = where.And(base_message._.subtime <= txtEnd.Value);
            }

            if (ddlstate.SelectedIndex > 0)
            {
                where = where.And(base_message._.status == ddlstate.Value);
            }

            FromSection<base_message> from = RicciDatabase.Default.From<base_message>().Where(where).OrderBy(base_message._.subtime.Desc);

            pager.RecordCount = from.Count();

            using (IDataReader reader = from.Page(pager.PageSize, pager.CurrentPageIndex).ToDataReader())
            {
                rptnewslist.DataSource = reader;
                rptnewslist.DataBind();
            }

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            pager.CurrentPageIndex = 1;
            bindData();
        }

        /// <summary>
        /// 获取路径
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        protected string getUrl(object mid)
        {
            return JavaScript.ShowModalDialogString("message.aspx?mid=" + mid.ToString(), 500, 500, null, null, null, null, true);
        }
    }
}
